import { BaseWindow } from "../../../../component/window/BaseWindow";
import { ILayer } from "../../../../mvc/interfaces/ILayer";
import { Language } from "../../../../../extend/language/Language";
import { GImageBitmap } from "../../../../../com/mui/controls/GImageBitmap";
import { ImagesConst } from "../../../resource/ImagesConst";
import { ObjCreate } from "../../common/ObjCreate";
import { GTextFormat } from "../../../../common/GTextFormat";
import { FontUtil } from "../../../../common/font/FontUtil";
import { ResFileConst } from "../../../resource/ResFileConst";
import { GuildAnimalModelPanel } from "./GuildAnimalModelPanel";
import { GlobalStyle } from "../../../../common/global/GlobalStyle";
import { TGuildAltar } from "../../../../../Message/Db/Tables/TGuildAltar";
import { BossConfig } from "../../../resource/BossConfig";
import { GLoadedButton } from "../../../../../com/mui/controls/GLoadedButton";
import { GuildAltarConfig } from "../../../resource/GuildAltarConfig";
import { Cache } from "../../../cache/Cache";
import { MsgManager } from "../../../manager/MsgManager";
import { Dispatcher } from "../../../../mvc/core/Dispatcher";
import { DataEvent } from "../../../events/DataEvent";
import { EventName } from "../../../mvc/EventName";
import { GButton } from "../../../../../com/mui/controls/GButton";
import { BossInfo } from "../../../resource/info/BossInfo";
type int = number;
//class GuildAnimalGetWindow
    
    export  class GuildAnimalGetWindow extends BaseWindow
    {
        constructor(arg1: ILayer=null)
        {
            super(arg1);
            this.setSize(475, 450);
            this.titleHeight = 28;
            this.title = Language.getString(57511);
            return;
        }

        protected /* override */ createChildren(): void
        {
            super.createChildren();
            this.addChild(new GImageBitmap(ImagesConst.GuildAnimalBg0, 57, 45));
            this._nameTxt = ObjCreate.createTextField("", 0, 75, 475, 20, this, new GTextFormat(FontUtil.songtiName, 16, 15788607, true));
            this._nameTxt.autoSize = flash.text.TextFieldAutoSize.CENTER;
            this._leftBtn = ObjCreate.createGLoadedButton(ResFileConst.GuildAnimalLeft, 10, 180, 42, 48, this);
            this._leftBtn.name = "left";
            this._rightBtn = ObjCreate.createGLoadedButton(ResFileConst.GuildAnimalRight, 420, 180, 42, 48, this);
            this._rightBtn.name = "right";
            this._leftBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onTurnBtnClickHandler);
            this._rightBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onTurnBtnClickHandler);
            this._modelPanel = new GuildAnimalModelPanel();
            this._modelPanel.x = 240;
            this._modelPanel.y = 290;
            this.addChild(this._modelPanel);
            ObjCreate.createTextField(Language.getString(57517), 60, 360, 220, 20, this);
            this._bnameTxt = ObjCreate.createTextField("", 130, 360, 220, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(57518), 60, 380, 220, 20, this);
            this._conditionTxt = ObjCreate.createTextField("", 130, 380, 220, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(57519), 60, 400, 220, 20, this);
            this._costTxt = ObjCreate.createTextField("0", 130, 400, 220, 20, this, GlobalStyle.textFormat6);
            ObjCreate.createTextField(Language.getString(57146), 60, 420, 220, 20, this);
            this._moneyTxt = ObjCreate.createTextField("0", 130, 420, 220, 20, this, GlobalStyle.textFormat6);
            this._getBtn = ObjCreate.createGButton(Language.getString(57516), 275, 385, 70, 28, this);
            this._getBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onGetBtnClickHandler);
            return;
        }

        public updateByGuildAltar(arg1: TGuildAltar): void
        {
            var loc1="";
            if (arg1) 
            {
                this._curLevel = arg1.level;
                this._bossInfo = BossConfig.instance.getInfoByCode(arg1.bossId);
                this._modelPanel.updateModelByCode(arg1.bossId);
                this._costResource = arg1.resourceCost;
                loc1 = this._bossInfo.boss.name;
                this._nameTxt.text = loc1;
                this._bnameTxt.text = loc1;
                this._conditionTxt.text = Language.getStringByParam(57543, arg1.level);
                this._costTxt.text = this._costResource.toString();
            }
            return;
        }

        public updateGuildMoney(arg1: int): void
        {
            this._moneyTxt.text = arg1.toString();
            return;
        }

        /* internal  */onTurnBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=(arg1.target as GLoadedButton).name;
            if (loc1 != "left") 
            {
                if (loc1 == "right") 
                {
                    this.updateByGuildAltar(GuildAltarConfig.instance.getConfigByLevel(this._curLevel + 1));
                }
            }
            else 
            {
                this.updateByGuildAltar(GuildAltarConfig.instance.getConfigByLevel((this._curLevel - 1)));
            }
            return;
        }

        /* internal  */onGetBtnClickHandler(arg1: Object /* flash.events.Event */): void
        {
            var loc1=Cache.instance.guild.myGuildInfo.money - this._costResource >= 0;
            if (!loc1) 
            {
                MsgManager.showRollTipsMsg(Language.getString(57524));
                return;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.GuildAnimalGet, this._curLevel));
            return;
        }

        /* internal */ /* var */_nameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_modelPanel: GuildAnimalModelPanel;

        /* internal */ /* var */_leftBtn: GLoadedButton;

        /* internal */ /* var */_rightBtn: GLoadedButton;

        /* internal */ /* var */_bnameTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_conditionTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_costTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_moneyTxt: Object /* flash.text.TextField */;

        /* internal */ /* var */_getBtn: GButton;

        /* internal */ /* var */_curLevel: int;

        /* internal */ /* var */_costResource: int;

        /* internal */ /* var */_bossInfo: BossInfo;
    }
